import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/modules/mine/view/mine_bottom_phone.dart';
import 'package:honeypotflutter/modules/mine/view/mine_headerInfo.dart';
import 'package:honeypotflutter/modules/mine/view/mine_wallCard.dart';
import 'package:honeypotflutter/public/public_get.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import 'package:honeypotflutter/publicBussine/bussine_image.dart';
import 'package:honeypotflutter/publicBussine/loginInfo/bussine_userInfo.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_item.dart';
import 'package:honeypotflutter/public/views/public_appBar.dart';
import 'package:honeypotflutter/public/views/public_scrollView.dart';
import 'package:honeypotflutter/router/bussine_router_url.dart';
import 'logic.dart';

class MinePage extends StatefulWidget {
  const MinePage({Key? key}) : super(key: key);

  @override
  State<MinePage> createState() => _MinePageState();
}

class _MinePageState extends State<MinePage> {
  final MineLogic logic = Get.put(MineLogic());

  final UserInfoLogic _logic = Get.find<UserInfoLogic>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: MGColors.whileColor,
      appBar: HLAppBar(showBackLeading: false),
      body: HLScrollView(
        padding: EdgeInsets.only(left: 16, right: 16),
        children: [
          MineHeaderInfo(),
          SizedBox(height: 20),
          MineWallCard(),
          MGItems(
            padding: EdgeInsets.only(top: 25),
            leadIcon: MGImage.image("mine_preference", type: ImagePathType.mine),
            leadTitle: "收集人偏好设置",
            trailingIcon: MGImage.image("public_next", type: ImagePathType.public),
            action: () {
              HLGet.toNamed(MGRouterUrl.preferences_list);
            },
          ),
          MGItems(
            padding: EdgeInsets.only(top: 25),
            leadIcon: MGImage.image("mine_set", type: ImagePathType.mine),
            leadTitle: "设置",
            trailingIcon: MGImage.image("public_next", type: ImagePathType.public),
            action: () {
              HLGet.toNamed(MGRouterUrl.setting);
            },
          ),
          GetBuilder<UserInfoLogic>(
              init: UserInfoLogic(),
              builder: (controller) {
                return MGItems(
                  padding: EdgeInsets.only(top: 25),
                  leadIcon: MGImage.image("mine_freePay", type: ImagePathType.mine),
                  leadTitle: "支付宝免密支付",
                  trailingTitle: ((controller.userInfo.isAliWithHoldingPaySigned != null) && controller.userInfo.isAliWithHoldingPaySigned!) ? "已开通" : "未开通",
                  trailingIcon: MGImage.image("public_next", type: ImagePathType.public),
                  action: () {
                    if (((controller.userInfo.isAliWithHoldingPaySigned != null) && controller.userInfo.isAliWithHoldingPaySigned!)) {
                      HLGet.toNamed(MGRouterUrl.freePay_close);
                    } else {
                      HLGet.toNamed(MGRouterUrl.freePay_open);
                    }
                  },
                );
              }),
          GetBuilder<UserInfoLogic>(
              init: UserInfoLogic(),
              builder: (controller) {
                return MGItems(
                  padding: EdgeInsets.only(top: 25),
                  leadIcon: MGImage.image("mine_exchange", type: ImagePathType.mine),
                  leadTitle: "选择投递支付方式",
                  trailingTitle: (controller.userInfo.userFirstChoicePayType != null && controller.userInfo.userFirstChoicePayType! == 1) ? "支付宝免密支付" : "账户余额",
                  trailingIcon: MGImage.image("public_next", type: ImagePathType.public),
                  action: () {
                    HLGet.toNamed(MGRouterUrl.freePay_exchange);
                  },
                );
              })
        ],
      ),
      bottomSheet: MineBottomPhone(),
    );
  }

  @override
  void dispose() {
    Get.delete<MineLogic>();
    super.dispose();
  }
}
